package com.btex.app;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.btex.app.adapter.MyFragmentAdapter;
import com.btex.app.adapter.TradesAdapter;
import com.btex.app.entity.BtexInfo;
import com.btex.app.entity.TexchangeRateInfo;
import com.btex.app.entity.TradeInfo;
import com.btex.app.kine.kline.KData;
import com.btex.app.kine.kline.NewKLineView;
import com.btex.app.tools.DensityUtil;
import com.btex.app.tools.MicroAVLIDialog;
import com.btex.app.tools.SharedPreferencesUtil;
import com.btex.app.tools.Tools;
import com.btex.app.treaty.KChengJiaoFragment;
import com.btex.app.treaty.KWeiTuoFragment;
import com.btex.app.treaty.MyViewPager;
import com.google.gson.Gson;
import com.guoziwei.klinelib.chart.KLineView;
import com.guoziwei.klinelib.model.HisData;
import com.lidroid.xutils.http.RequestParams;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class KLineActivity extends BaseActivity {


    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_menu)
    TextView mTvMenu;
    @BindView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @BindView(R.id.activity_b_k_name)
    TextView mActivityBKName;
    @BindView(R.id.activity_b_k_money)
    TextView mActivityBKMoney;
    @BindView(R.id.activity_b_k_rise)
    TextView mActivityBKRise;
    @BindView(R.id.activity_b_k_height)
    TextView mActivityBKHeight;
    @BindView(R.id.activity_b_k_vol)
    TextView mActivityBKVol;
    @BindView(R.id.activity_b_k_lowest)
    TextView mActivityBKLowest;
    @BindView(R.id.activity_b_k_shaixuan)
    ImageView mActivityBKShaixuan;
    @BindView(R.id.activity_b_k_full)
    ImageView mActivityBKFull;
    @BindView(R.id.activity_kine_k)
    KLineView mKLineView;
    @BindView(R.id.activity_recy_k)
    RecyclerView mActivityRecyK;
    @BindView(R.id.ll_shidang)
    LinearLayout mLlShidang;
    @BindView(R.id.activity_k_time)
    TextView mActivityKTime;
    @BindView(R.id.activity_b_k_full_tv)
    TextView mActivityBKFullTv;
    @BindView(R.id.activity_kline_zhi_biao)
    TextView mActivityKlineZhiBiao;
    @BindView(R.id.tv_otc_la)
    ImageView mTvOtcLa;
    @BindView(R.id.kine_activity_five)
    TextView mKineActivityFive;
    @BindView(R.id.kine_activity_fifteen)
    TextView mKineActivityFifteen;
    @BindView(R.id.kine_activity_one_hours)
    TextView mKineActivityOneHours;
    @BindView(R.id.kine_activity_one_day)
    TextView mKineActivityOneDay;
    @BindView(R.id.kine_activity_full)
    TextView mKineActivityFull;
    @BindView(R.id.kine_activity_thirty)
    TextView mKineActivityThirty;
    @BindView(R.id.activity_futures_full)
    LinearLayout mActivityFuturesFull;
    @BindView(R.id.activity_lin_zhishu)
    LinearLayout mActivityLinZhishu;
    @BindView(R.id.activity_k_heli)
    TextView mActivityKHeli;
    @BindView(R.id.activity_lin_heli)
    LinearLayout mActivityLinHeli;
    @BindView(R.id.activity_kine_24)
    TextView mActivityKine24;
    @BindView(R.id.treaty_tv_weituo)
    TextView mTreatyTvWeituo;

    @BindView(R.id.activity_kline_cny)
    TextView activity_kline_cny;
    @BindView(R.id.treaty_tv_zuixin_chengiao)
    TextView mTreatyTvZuixinChengiao;
    @BindView(R.id.activity_k_viewpager)
    MyViewPager mActivityKViewpager;
    @BindView(R.id.activity_mairu)
    Button mActivityMairu;
    @BindView(R.id.activity_maichu)
    Button mActivityMaichu;

    @BindView(R.id.K_xian_lin)
    LinearLayout K_xian_lin;
    @BindView(R.id.activity_jiaoyi)
    LinearLayout mActivityJiaoyi;
    @BindView(R.id.activity_lin_jiaoyi_liang)
    LinearLayout mActivityLinJiaoyiLiang;
    private List<HisData> mHisDatas;
    public String mPair;
    private Object mListInfo;

    private TradesAdapter mTradesAdapter;
    private MicroAVLIDialog mMicroAVLIDialog;
    public boolean isShow;
    private TextView mPop_clssify_types_d;
    public boolean isActivityShow;
    public boolean isShowKdj;

    public String times = "5";
    private NewKLineView mKineview;
    public int size = 0;
    public String activitytype = "1";
    public String mPrice_float_num = "6";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kline);
        ButterKnife.bind(this);

//        mActivityJiaoyi.setVisibility(View.GONE);
        mActivityLinJiaoyiLiang.setVisibility(View.GONE);
        mTreatyTvWeituo.setSelected(true);
        mRlTitle.setBackgroundResource(R.color.FuturesKLineActivity_color);
        mIvBack.setBackgroundResource(R.color.FuturesKLineActivity_color);
        mActivityLinZhishu.setVisibility(View.INVISIBLE);
        mActivityLinHeli.setVisibility(View.INVISIBLE);

        mKineActivityFive.setSelected(true);

        initListener();

        mKineview = (NewKLineView) findViewById(R.id.new_kine_view);
        mKineview.setCrossHairMoveMode(2);

        mKineview.setOnRequestDataListListener(new NewKLineView.OnRequestDataListListener() {
            @Override
            public void requestData() {

            }
        });

        mActivityRecyK.setNestedScrollingEnabled(false);
        mPair = (String) getIntent().getExtras().get("pair");

        if (!TextUtils.isEmpty(mPair)) {
            String[] split = mPair.split("_");
            String s = split[0];
            String s1 = split[1];
            mTvTitle.setText(s + "/" + s1);
            mActivityBKName.setText(s + "/" + s1);
        }
        mMicroAVLIDialog = new MicroAVLIDialog(this);
        mMicroAVLIDialog.setCanceledOnTouchOutside(true);
        mMicroAVLIDialog.show();
        initRecyClerview();
        geTexchangeRate();
        getListInfo();
        initData();
        initInfo("1m");
        initOnclik();
//        mTvTitle.setText("k线");
//        mTvTitle.setText("k线");


        double d = 88.88;
        long l = Math.round(d);
        initviewpager();
        initOnclikLIstener();

    }

    private void initviewpager() {
        ArrayList<Fragment> fragments = new ArrayList<>();
//        fragments.add(new KWeiTuoFragment());
        fragments.add(new KWeiTuoFragment());
        fragments.add(new KChengJiaoFragment());

        ArrayList<String> strings = new ArrayList<>();
        strings.add("历史委托");
        strings.add("已成交");
        strings.add("已平仓位");
        mActivityKViewpager.setAdapter(new MyFragmentAdapter(getSupportFragmentManager(), fragments, strings));
        mActivityKViewpager.setOffscreenPageLimit(2);
        mActivityKViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                if (position == 0) {
                    mTreatyTvWeituo.setSelected(true);
                    mTreatyTvZuixinChengiao.setSelected(false);
                } else {
                    mTreatyTvWeituo.setSelected(false);
                    mTreatyTvZuixinChengiao.setSelected(true);
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {


            }
        });
    }

    private void initListener() {

//        委托
        mTreatyTvWeituo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivityKViewpager.setCurrentItem(0, false);
                mTreatyTvWeituo.setSelected(true);
                mTreatyTvZuixinChengiao.setSelected(false);
            }
        });
        mTreatyTvZuixinChengiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivityKViewpager.setCurrentItem(1, false);
                mTreatyTvWeituo.setSelected(false);
                mTreatyTvZuixinChengiao.setSelected(true);
            }
        });

        mKineActivityFull.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                setStat();
                mKineActivityFull.setSelected(true);
                View contentView = View.inflate(cxt, R.layout.pop_kline, null);


                TextView pop_new_k_1_day = (TextView) contentView.findViewById(R.id.pop_new_k_1_day);
                TextView pop_new_k_1_week = (TextView) contentView.findViewById(R.id.pop_new_k_1_week);
                TextView pop_new_k_30 = (TextView) contentView.findViewById(R.id.pop_new_k_30);
                TextView pop_new_k_5 = (TextView) contentView.findViewById(R.id.pop_new_k_5);

                //获取屏幕宽高
                DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
                //屏幕宽
                int widthPixels = displayMetrics.widthPixels;
                //屏幕高
                int heightPixels = displayMetrics.heightPixels;

                final PopupWindow pop = new PopupWindow(contentView, widthPixels, 100);
                int[] location = new int[2];
                v.getLocationInWindow(location);
                pop.setOutsideTouchable(true);
                pop.setBackgroundDrawable(cxt.getResources().getDrawable(R.color.transparent));
                pop.showAtLocation(K_xian_lin, Gravity.CENTER | Gravity.TOP, DensityUtil.dip2px(cxt, 72), location[1] + DensityUtil.dip2px(cxt, 30));
                pop_new_k_1_day.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("1天");
                        times = "1d";
                        initInfo("1d");
                        pop.dismiss();
                    }
                });


                pop_new_k_1_week.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("1周");
                        times = "1w";
                        initInfo("1m");

                        pop.dismiss();
                    }
                });


                pop_new_k_30.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("30分");
                        times = "30";
                        initInfo("30m");
                        pop.dismiss();

                    }
                });


                pop_new_k_5.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mKineActivityFull.setText("5分");
                        times = "5";
                        initInfo("5m");
                        pop.dismiss();

                    }
                });

            }
        });

////        5分
//        mKineActivityFive.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mKineActivityFull.setText("更多");
//                times = "5";
//                setStat();
//                mKineActivityFive.setSelected(true);
//                initInfo("5m");
//            }
//        });
//
////        15分
//        mKineActivityFifteen.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mKineActivityFull.setText("更多");
//                times = "15";
//                setStat();
//                mKineActivityFifteen.setSelected(true);
//                initInfo("15m");
//            }
//        });
//
//        mKineActivityThirty.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mKineActivityFull.setText("更多");
//                times = "30";
//                setStat();
//                mKineActivityThirty.setSelected(true);
//                initInfo("30m");
//            }
//        });
//
////        1小时
//        mKineActivityOneHours.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mKineActivityFull.setText("更多");
//                times = "1h";
//                setStat();
//                mKineActivityOneHours.setSelected(true);
//                initInfo("1h");
//            }
//        });
//
////        一天
//
//        mKineActivityOneDay.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mKineActivityFull.setText("更多");
//                times = "1d";
//                setStat();
//                mKineActivityOneDay.setSelected(true);
//                initInfo("1d");
//            }
//        });

        //        5分
        mKineActivityFive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mKineActivityFull.setText("更多");
                size = 0;

                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }
                times = "1";
                setStat();
                mKineActivityFive.setSelected(true);
                initInfo("1m");
            }
        });

//        15分
        mKineActivityFifteen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "15";
                setStat();
                mKineActivityFifteen.setSelected(true);
                initInfo("15m");
            }
        });

        mKineActivityThirty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "30";
                setStat();
                mKineActivityThirty.setSelected(true);
                initInfo("30m");
            }
        });

//        1小时
        mKineActivityOneHours.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "1h";
                setStat();
                mKineActivityOneHours.setSelected(true);
                initInfo("1h");
            }
        });

//        一天

        mKineActivityOneDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKineActivityFull.setText("更多");
                size = 0;
                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.show();
                }

                times = "4h";
                setStat();
                mKineActivityOneDay.setSelected(true);
                initInfo("4h");
            }
        });


    }

    private void setStat() {
        mKineActivityOneDay.setSelected(false);
        mKineActivityOneHours.setSelected(false);
        mKineActivityFifteen.setSelected(false);
        mKineActivityFive.setSelected(false);
        mKineActivityThirty.setSelected(false);
        mKineActivityFull.setSelected(false);
    }


    private void initOnclikLIstener() {


        mActivityKlineZhiBiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showZhiBiao(KLineActivity.this, v);
            }
        });

        mActivityKTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                showPoplassifye(KLineActivity.this, view);
            }
        });

        mActivityBKShaixuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                showPoplassifye(KLineActivity.this, view);
            }
        });


    }

    private void initOnclik() {


        mActivityMairu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mActivityMaichu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mActivityFuturesFull.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(KLineActivity.this, KLineFullActivity.class);
                intent.putExtra("pair", mPair);
                startActivity(intent);
            }
        });


        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void initRecyClerview() {

        mActivityRecyK.setLayoutManager(new LinearLayoutManager(this));
        mTradesAdapter = new TradesAdapter(null);
    }

    @Override
    public void setData() {


    }

    @Override
    public void onClick(View view) {

    }


    private void initInfo(String time) {

//        if (mMicroAVLIDialog != null) {
//            mMicroAVLIDialog.show();
//        }

        Log.i("wlefjwejifowe", time);
        RequestParams params = new RequestParams();
        params.addQueryStringParameter("limit", "200");
        params.addQueryStringParameter("type", time);
        params.addQueryStringParameter("symbol", mPair);
        int num = (int) ((Math.random() * 9 + 1) * 100000);


        OkGo.<String>get(Config.URL_APP_BTEX + "?rnd=" + String.valueOf(num)).tag(this).params("limit", "200").params("type", time).params("symbol", mPair).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                String result = response.body().toString();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {

                        if (mMicroAVLIDialog != null) {
                            mMicroAVLIDialog.dismiss();
                        }
                        setKineData(result);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();

                }
            }

            @Override
            public void onFinish() {
                super.onFinish();

                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.dismiss();
                }
            }
        });

//        HttpHandler<String> send = new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.URL_APP_BTEX + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
////                mMicroAVLIDialog.dismiss();
//                if (mMicroAVLIDialog != null) {
//                    mMicroAVLIDialog.dismiss();
//                }
//                setKineData(responseInfo.result);
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
////                mMicroAVLIDialog.dismiss();
//                Toast.makeText(cxt, msg, Toast.LENGTH_SHORT).show();
//
//            }
//        });

    }


    public void getListInfo() {
        RequestParams params = new RequestParams();
        params.addQueryStringParameter("pair", mPair);
        int num = (int) ((Math.random() * 9 + 1) * 100000);

        OkGo.<String>get(Config.URL_PAIR_HISTORY + "?rnd=" + String.valueOf(num)).tag(this).params("pair", mPair).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                String result = response.body().toString();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {

                        Gson gson = new Gson();
                        TradeInfo tradeInfo = gson.fromJson(result, TradeInfo.class);
                        List<TradeInfo.DataBean.ListBean> list = tradeInfo.getData().getList();
                        mActivityRecyK.setAdapter(mTradesAdapter);
                        mTradesAdapter.SetTyee("1");
                        mTradesAdapter.setNewData(list);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();

                }
            }
        });


//        new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.URL_PAIR_HISTORY + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                String result = responseInfo.result;
////                Log.i("lwefjwjefoiwe", result);
//                Gson gson = new Gson();
//                TradeInfo tradeInfo = gson.fromJson(result, TradeInfo.class);
//                List<TradeInfo.DataBean.ListBean> list = tradeInfo.getData().getList();
//
//                mActivityRecyK.setAdapter(mTradesAdapter);
//                mTradesAdapter.SetTyee("1");
//                mTradesAdapter.setNewData(list);
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//
//            }
//        });
    }


    private void geTexchangeRate() {
        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(this);
        String lang = "";
        final boolean isEngilsh = sharedPreferences.getBoolean("isEngilsh", false);
        if (isEngilsh) {
            lang = "en";

        } else {
            lang = "zh_cn";
        }


        int num = (int) ((Math.random() * 9 + 1) * 100000);


        OkGo.<String>get(Config.URL_PAIR + "?rnd=" + String.valueOf(num)).tag(this).params(Config.KEY_PAIR, mPair).params("lang", lang).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                String result = response.body().toString();


                Log.i("wefwjeifjwoiejfw", result);

                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {
                        Gson gson = new Gson();
                        TexchangeRateInfo texchangeRateInfo = gson.fromJson(result, TexchangeRateInfo.class);
                        String change_24h = texchangeRateInfo.getData().getChange_24h();
                        String trade_price = texchangeRateInfo.getData().getTrade_price();
                        String rate_price = texchangeRateInfo.getData().getRate_price();

                        mPrice_float_num = texchangeRateInfo.getData().getPrice_float_num();

                        Log.i("wieufiwugefwegfuwegfiwe", mPrice_float_num);
                        Log.i("weifowijefjwoief", rate_price);

                        double v1 = Double.valueOf(trade_price) * Double.valueOf(rate_price);
                        String trim = Tools.round(v1, Integer.valueOf(mPrice_float_num)).toString().trim();
                        activity_kline_cny.setVisibility(View.VISIBLE);
                        activity_kline_cny.setText("≈￥" + trim);
                        Double aDouble1 = Double.valueOf(change_24h);

                        if (aDouble1 < 0) {
                            double v = aDouble1 * 100;
                            String s3 = doubleStr(v);
                            mActivityBKRise.setText(s3 + "%");
                            mActivityBKRise.setTextColor(getResources().getColor(R.color.red));
                            mActivityBKMoney.setTextColor(getResources().getColor(R.color.red));

                        } else {
                            Double aDouble = Double.valueOf(change_24h);
                            double v = aDouble * 100;
                            String s3 = doubleStr(v);
                            mActivityBKRise.setText("+" + s3 + "%");
                            mActivityBKRise.setTextColor(getResources().getColor(R.color.bg_green));
                            mActivityBKMoney.setTextColor(getResources().getColor(R.color.bg_green));
                        }
                        mActivityBKHeight.setText(texchangeRateInfo.getData().getHigh());
                        mActivityBKLowest.setText(texchangeRateInfo.getData().getLow());
                        mActivityBKVol.setText(texchangeRateInfo.getData().getTotal());
                        mActivityBKMoney.setText(texchangeRateInfo.getData().getTrade_price());
                        String Total = Tools.round(Double.valueOf(texchangeRateInfo.getData().getTotal()), Integer.valueOf(mPrice_float_num)).toString().trim();
                        mActivityKine24.setText(Total);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });


//        RequestParams params = new RequestParams();
//        params.addQueryStringParameter(Config.KEY_PAIR, mPair);
//        params.addQueryStringParameter("lang", lang);
//        new HttpUtils().send(HttpRequest.HttpMethod.GET, Config.URL_PAIR + "?rnd=" + String.valueOf(num), params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                String result = responseInfo.result;
//                Log.i("kwjehfuwihefwsdsdeui", responseInfo.result);
//                try {
//                    JSONObject jsonObject = new JSONObject(result);
//                    if ("1".equals(jsonObject.getString(Config.KEY_CODE))) {
//
//                        Gson gson = new Gson();
//                        TexchangeRateInfo texchangeRateInfo = gson.fromJson(result, TexchangeRateInfo.class);
//                        String change_24h = texchangeRateInfo.getData().getChange_24h();
//                        String trade_price = texchangeRateInfo.getData().getTrade_price();
//                        String rate_price = texchangeRateInfo.getData().getRate_price();
//                        String price_float_num = texchangeRateInfo.getData().getPrice_float_num();
//
//                        double v1 = Double.valueOf(trade_price) * Double.valueOf(rate_price);
//                        String trim = Tools.round(v1, 2).toString().trim();
//                        activity_kline_cny.setVisibility(View.VISIBLE);
//                        activity_kline_cny.setText("≈￥" + trim);
//                        Double aDouble1 = Double.valueOf(change_24h);
//
//                        if (aDouble1 < 0) {
//                            double v = aDouble1 * 100;
//                            String s3 = doubleStr(v);
//                            mActivityBKRise.setText(s3 + "%");
//                            mActivityBKRise.setTextColor(getResources().getColor(R.color.red));
//                            mActivityBKMoney.setTextColor(getResources().getColor(R.color.red));
//
//                        } else {
//
//                            Double aDouble = Double.valueOf(change_24h);
//                            double v = aDouble * 100;
//                            String s3 = doubleStr(v);
//                            mActivityBKRise.setText("+" + s3 + "%");
//                            mActivityBKRise.setTextColor(getResources().getColor(R.color.bg_green));
//                            mActivityBKMoney.setTextColor(getResources().getColor(R.color.bg_green));
//
//                        }
//                        mActivityBKHeight.setText(texchangeRateInfo.getData().getHigh());
//                        mActivityBKLowest.setText(texchangeRateInfo.getData().getLow());
//                        mActivityBKVol.setText(texchangeRateInfo.getData().getTotal());
//                        mActivityBKMoney.setText(texchangeRateInfo.getData().getTrade_price());
//
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(HttpException error, String msg) {
//
//            }
//        });
    }


    public String doubleStr(Double d) {
        DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");// 格式化设置
        String format = decimalFormat.format(d);
        return format;
    }


    private Handler handler = new Handler() {

    };
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {

            if (isActivityShow) {
                geTexchangeRate();
                getListInfo();

//                if (times.equals("15")) {
//
//                    Log.i("welfjwpiejfoiwfe", "1");
//                    initInfo("15m");
//                } else if (times.equals("5")) {
//                    Log.i("welfjwpiejfoiwfe", "2");
//                    initInfo("5m");
//                } else if (times.equals("30")) {
//                    Log.i("welfjwpiejfoiwfe", "3");
//                    initInfo("30m");
//                } else if (times.equals("1h")) {
//                    Log.i("welfjwpiejfoiwfe", "4");
//                    initInfo("1h");
//
//                } else if (times.equals("1")) {
//                    Log.i("welfjwpiejfoiwfe", "5");
//                    initInfo("1m");
//                } else if (times.equals("4h")) {
//                    Log.i("welfjwpiejfoiwfe", "6");
//                    initInfo("4h");
//                } else if (times.equals("1d")) {
//                    Log.i("welfjwpiejfoiwfe", "7");
//                    initInfo("1d");
//                } else if (times.equals("1w")) {
//
//                    Log.i("welfjwpiejfoiwfe", "8");
//                    initInfo("1w");
//                }

                handler.postDelayed(this, 3000);
            } else {
                return;
            }


        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        isActivityShow = true;
        handler.postDelayed(runnable, 0);

    }

    @Override
    protected void onPause() {
        super.onPause();
//        Log.i("kwjehfuwihefweui2323232", "1");
        isActivityShow = false;
        OkGo.getInstance().cancelTag(this);

    }


    private void showZhiBiao(Context cxt, View view) {


        View contentView = View.inflate(cxt, R.layout.pop_classify_zhi_biao, null);
        TextView pop_clssify_kdj = (TextView) contentView.findViewById(R.id.pop_clssify_kdj);
        TextView pop_clssify_macd = (TextView) contentView.findViewById(R.id.pop_clssify_macd);

        final PopupWindow pop = new PopupWindow(contentView, 150, 300);
        int[] location = new int[2];
        view.getLocationInWindow(location);
        pop.setOutsideTouchable(true);
        pop.setBackgroundDrawable(cxt.getResources().getDrawable(R.color.transparent));

        if (isShowKdj) {
            pop.dismiss();
        } else {
            pop.showAtLocation(view, Gravity.RIGHT | Gravity.TOP, DensityUtil.dip2px(cxt, 72), location[1] + DensityUtil.dip2px(cxt, 30));
        }
        isShowKdj = !isShowKdj;

        pop_clssify_kdj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKLineView.showKdj();
                pop.dismiss();
            }
        });


        pop_clssify_macd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mKLineView.showMacd();
                pop.dismiss();

            }
        });


    }


    private void setKineData(String result) {
        Gson gson = new Gson();
        BtexInfo btexInfo = gson.fromJson(result, BtexInfo.class);
        List<List<String>> lists = btexInfo.getData().getLists();

        List<KData> dataList = new ArrayList<>();

        double openPrice;
        double closePrice;
        double maxPrice;
        double minPrice;
        double volume;
        long kinetime;


        if (lists.size() > 0) {

            for (int i = 0; i < lists.size(); i++) {

//            时间
                kinetime = Long.valueOf(lists.get(i).get(0));
//            开盘价
                openPrice = Double.valueOf(lists.get(i).get(1));
//            最高价
                maxPrice = Double.valueOf(lists.get(i).get(2));
//            最低价
                minPrice = Double.valueOf(lists.get(i).get(3));
//            收盘价
                closePrice = Double.valueOf(lists.get(i).get(4));
//            成交量
                volume = Double.valueOf(lists.get(i).get(5));
//            填充数据
                dataList.add(new KData(kinetime, openPrice, closePrice, maxPrice, minPrice, volume));
//            最后的成交价就是开盘价
                openPrice = closePrice;

            }


            if (size > 0) {
                mKineview.resetDataList(dataList);
            } else {
                mKineview.initKDataList(dataList);
            }

            mKineview.setDeputyPicShow(true);

            size++;

        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
    }


}
